package com.azusa.xbjy.dao;

import com.azusa.xbjy.entity.Meeting;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface MeetingMapper {

    /**
     * 查询会议详情分页信息
     * @param title
     * @param status
     * @return
     */
    @Select("<script>" +
            "SELECT " +
            "meeting.id,  " +
            "meeting.dept_name AS deptName,  " +
            "meeting.dept_id AS deptId,  " +
            "meeting.title,  " +
            "meeting.publish_date AS publishDate,  " +
            "meeting.content,  " +
            "meeting.start_time AS startTime,  " +
            "meeting.`status`,  " +
            "meeting.end_time AS endTime,  " +
            "meeting.make_user AS makeUser " +
            "FROM " +
            "meeting " +
            "WHERE " +
            "meeting.title LIKE CONCAT('%',#{title},'%') " +
            "<if test='status!=null'>" +
            "AND " +
            "meeting.`status`=#{status}" +
            "</if>" +
            "</script>")
    List<Meeting> findPage(@Param("title")String title,@Param("status") String status);

    @Select("SELECT COUNT(*) FROM meeting_join WHERE m_id=#{meetingId}")
    int findArrivedNum(int meetingId);

    @Select("SELECT COUNT(*) FROM meeting_join WHERE u_id=#{uid} AND m_id=#{mid}")
    int findByUserIdAndMeetingId(int uid,int mid);

    @Insert("INSERT INTO `meeting_join`(`u_id`, `m_id`) VALUES (#{uid}, #{mid})")
    int join(int uid,int mid);

    @Delete("DELETE FROM `meeting_join` WHERE `u_id`=#{uid} AND `m_id`=#{mid}")
    int noJoin(int uid,int mid);
}
